package com.yw.swagger.service.serviceImpl;

import com.sun.org.apache.xpath.internal.operations.Bool;
import com.yw.swagger.mapper.AuthorMapper;
import com.yw.swagger.model.AppAuthor;
import com.yw.swagger.service.AuthorService;
import com.yw.swagger.tool.Utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Abeiv
 * @Description:
 * @Date: 2019/10/26 10:43
 */
@Service
public class AuthorServiceImpl implements AuthorService {

    @Autowired
    private AuthorMapper authorMapper;

    @Override
    public int addAuthor(AppAuthor author) {

        return authorMapper.addAuthor(author);
    }

    @Override
    public int delAuthor(AppAuthor author) {
        return authorMapper.delAuthor(author);
    }

    @Override
    public int updateAuthor(AppAuthor author) {
        return authorMapper.updateAuthor(author);
    }

    @Override
    public List<AppAuthor> selectAuthorList() {
        return authorMapper.selectAuthorList();
    }

    @Override
    public AppAuthor selectAuthorById(String id) {
        return authorMapper.selectAuthorById(id);
    }

    @Override
    public AppAuthor selectAuthorByCode(String code) {
        return authorMapper.selectAuthorByCode(code);
    }

    @Override
    public Boolean forList(List<AppAuthor> l,String sign){
        Boolean flag = false;
        for (int i = 0; i < l.size(); i++){
            if(l.get(i).getAuthorNum().equals(sign)){
                flag = true;
                if(l.get(i).getAuthorFlg() == 0){
                    // 修改已使用
                    AppAuthor a = l.get(i);
                    a.setAuthorFlg(1);
                    a.setAuthorNumUseDate(DateUtils.getNowDate());
                    updateAuthor(a);
                }
                break;
            }
        }
        return flag;
    }
}
